<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 容器 */
        .materialInput-container {
            position: relative;
            width: 200px;
            border-bottom: 1px solid #eee;
            box-sizing: border-box;
            margin: 100px auto;
        }

        /* 底部的线 */
        .materialInput-container .bar {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 0;
            border-bottom: 1px solid #87ceeb;
            transform-origin: center;
            transform: scaleX(0);
            transition: .2s ease all;
        }

        /* 输入框 */
        .materialInput-container .input {
            width: 100%;
            box-sizing: border-box;
            border: none;
            outline: none;
            padding: 5px;
            background-color: transparent;
        }

        /* label */
        .materialInput-container .label {
            color: #eee;
            font-size: 20px;
            position: absolute;
            z-index: -1;
            top: 0;
            left: 0;
            transform: translate(2px, 0);
            transition: all 0.3s;
        }

        /* 聚焦线样式 */
        .materialInput-container .input:focus~.bar {
            transform: scaleX(1);
        }

        /* 验证停留label */
        .materialInput-container .input:focus~.label,
        .materialInput-container .input:valid~.label {
            transform: translate(0, -100%);
            color: #87ceeb;
            font-size: 18px;
        }
    </style>
</head>

<body>
    <div class="materialInput-container">
        <input required type="text" name="" id="userName" class="input">
        <label class="label" for="userName">User Name</label>
        <span class="bar"></span>
    </div>
</body>

</html>